package com.beiding.editanalyzeframe;

/**
 * 一个行 内容只读
 *
 * @author 丁常磊
 * @date 2021/11/30 10:56
 */

public class Line {

    private String text = "";

    /**
     * 行号
     */
    private int lineNumber;

    /**
     * 哈希码
     */
    private int hash;

    Doc doc;

    /**
     * 上一行
     */
    Line pre;

    /**
     * 下一行
     */
    Line next;

    public Line(String text, int line) {
        this.text = text;
        this.lineNumber = line;
        this.hash = text.hashCode();
    }

    public String getText() {
        return text;
    }

    public String toText() {
        return text;
    }

    public int getLineNumber() {
        return lineNumber;
    }

    public Line getPre() {
        return pre;
    }

    public Line getNext() {
        return next;
    }

    public boolean eq(Line line) {
        if (line.hash != this.hash) {
            return false;
        }
        return this.getText().equals(line.getText());
    }

    public Doc getDoc() {
        return doc;
    }

    @Override
    public String toString() {
        return "[" + (lineNumber + 1) + "]-|" + toText();
    }
}
